home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / source.exe / POSIX / FIND / MISC.C < prev    next >
C/C++ Source or Header  |  1993-06-23  |  5KB  |  187 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Cimarron D. Taylor of the University of California, Berkeley.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  */
  36.  
  37. #ifndef lint
  38. static char sccsid[] = "@(#)misc.c    5.8 (Berkeley) 5/24/91";
  39. #endif /* not lint */
  40.  
  41. #ifdef DF_POSIX    /* DF_MSS */
  42. #include <misc.h>
  43. #include <bsdlib.h>
  44. #endif
  45.  
  46. #include <sys/types.h>
  47. #include <sys/stat.h>
  48. #ifdef _POSIX_SOURCE
  49. # include <errno.h>
  50. #else
  51. # include <sys/errno.h>
  52. #endif
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include "find.h"
  57. #if WIN_NT
  58.  
  59. extern void deglobulate __P((void));
  60. extern pid_t ppid;
  61. extern int globulation;
  62. #endif
  63.  
  64. /*
  65.  * brace_subst --
  66.  *    Replace occurrences of {} in s1 with s2 and return the result string.
  67.  */
  68. void
  69. #if __STDC__
  70. brace_subst (char *orig, char **store, char *path, int len)
  71. #else
  72. brace_subst(orig, store, path, len)
  73.     char *orig, **store, *path;
  74.     int len;
  75. #endif
  76. {
  77.     register int plen;
  78.     register char ch, *p;
  79.  
  80.     plen = strlen(path);
  81.     for (p = *store; (ch = *orig) != '\0'; ++orig)
  82.         if (ch == '{' && orig[1] == '}') {
  83.             while ((p - *store) + plen > len)
  84.                 if (!(*store = realloc(*store, len *= 2)))
  85.                     err("%s", strerror(errno));
  86.             bcopy(path, p, plen);
  87.             p += plen;
  88.             ++orig;
  89.         } else
  90.             *p++ = ch;
  91.     *p = '\0';
  92. }
  93.  
  94. /*
  95.  * queryuser --
  96.  *    print a message to standard error and then read input from standard
  97.  *    input. If the input is 'y' then 1 is returned.
  98.  */
  99. int
  100. #if __STDC__
  101. queryuser (register char **argv)
  102. #else
  103. queryuser(argv)
  104.     register char **argv;
  105. #endif
  106. {
  107.     int ch, first, nl;
  108.  
  109.     (void)fprintf(stderr, "\"%s", *argv);
  110.     while (*++argv)
  111.         (void)fprintf(stderr, " %s", *argv);
  112.     (void)fprintf(stderr, "\"? ");
  113.     (void)fflush(stderr);
  114.  
  115.     first = ch = getchar();
  116.     for (nl = 0;;) {
  117.         if (ch == '\n') {
  118.             nl = 1;
  119.             break;
  120.         }
  121.         if (ch == EOF)
  122.             break;
  123.         ch = getchar();
  124.     }
  125.  
  126.     if (!nl) {
  127.         (void)fprintf(stderr, "\n");
  128.         (void)fflush(stderr);
  129.     }
  130.         return(first == 'y');
  131. }
  132.  
  133. #if 1 || 0 /* DF_DSC: Because emalloc defined in df/misc.h */
  134. /*
  135.  * emalloc --
  136.  *    malloc with error checking.
  137.  */
  138. void *
  139. #if __STDC__
  140. emalloc (u_int len)
  141. #else
  142. emalloc(len)
  143.     u_int len;
  144. #endif
  145. {
  146.     void *p;
  147.  
  148.     if ((p = malloc(len)) != NULL)
  149.         return(p);
  150.     err("%s", strerror(errno));
  151.     /* NOTREACHED */
  152. }
  153. #endif
  154.  
  155. #if __STDC__
  156. #include <stdarg.h>
  157. #else
  158. #include <varargs.h>
  159. #endif
  160.  
  161. void
  162. #if __STDC__
  163. err(const char *fmt, ...)
  164. #else
  165. err(fmt, va_alist)
  166.     char *fmt;
  167.         va_dcl
  168. #endif
  169. {
  170.     va_list ap;
  171. #if __STDC__
  172.     va_start(ap, fmt);
  173. #else
  174.     va_start(ap);
  175. #endif
  176.     (void)fprintf(stderr, "find: ");
  177.     (void)vfprintf(stderr, fmt, ap);
  178.     va_end(ap);
  179.     (void)fprintf(stderr, "\n");
  180. #if WIN_NT
  181.     if (ppid == (pid_t) 1 && globulation == 0)
  182.         deglobulate();
  183. #endif
  184.     exit(EXIT_FAILURE);
  185.     /* NOTREACHED */
  186. }
  187.